<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('处理问题')" />
    <link href="/css/star/application.css" th:href="@{/css/star/application.css}" rel="stylesheet"/>

</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <div>
        <ul>
            <li class="wttw_head">问题提问</li>
        </ul>
    </div>
    <form class="form-horizontal m" id="form-dfQuestion-edit" th:object="${dfQuestion}">
        <input id="id" name="id" th:field="*{id}"  type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">用户名称：</label>
            <div class="col-sm-8">
                <input id="userName" name="userName" th:field="*{userName}" class="form-control" type="text" readonly>
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">用户id：</label>
            <div class="col-sm-8">
                <input id="userId" name="userId" th:field="*{userId}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">用户单位：</label>
            <div class="col-sm-8">
                <input id="userDept" name="userDept" th:field="*{userDept}" class="form-control" type="text" readonly>
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">用户单位id：</label>
            <div class="col-sm-8">
                <input id="userDeptId" name="userDeptId" th:field="*{userDeptId}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">联系方式：</label>
            <div class="col-sm-8">
                <input id="userPhone" name="userPhone" th:field="*{userPhone}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">问题处理结果：</label>
            <div class="col-sm-8">
                <input id="questionState" name="questionState" th:field="*{questionState}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">问题类型：</label>
            <div class="col-sm-8" style="padding-top: 3px;">
                <select name="questionType" class="form-control" >
                    <option value="2">处理</option>
                    <option value="3">解释</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">问题版本号：</label>
            <div class="col-sm-8">
                <select name="questionVersion" class="form-control" th:with="type=${@dict.getType('df_question_version')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">问题标题：</label>
            <div class="col-sm-8">
                <input id="questionTitle" name="questionTitle" th:field="*{questionTitle}" class="form-control" type="text" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">问题描述：</label>
            <div class="col-sm-8">
                <textarea id="questionContent" name="questionContent" th:field="*{questionContent}" class="form-control" type="text" readonly></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">附件：</label>
            <div class="col-sm-8">
                <ul th:each="file,fileStat : ${dfQuestion.files}"  style="padding-left: 0px;">
                    <img class="question_imgFile" th:src="${file.fileId}" th:if="${file.fileType=='png'||file.fileType=='jpg'}" data-id="${file.id}">
                    <img th:src="@{/img/tb_word.png}" th:if="${file.fileType=='docx'||file.fileType=='doc'}">
                    <img th:src="@{/img/tb_excel.png}" th:if="${file.fileType=='xls'||file.fileType=='xlsx'}">
                    <img th:src="@{/img/tb_zip.png}" th:if="${file.fileType=='zip'||file.fileType=='rar'}">
                    <img th:src="@{/img/tb_ppt.png}" th:if="${file.fileType=='ppt'||file.fileType=='pptx'}">
                </ul>
            </div>
        </div>



        <div class="form-group" th:each="list:${dfQuestionChild}">
            <ul>
                <li class="wttw_head">问题解决</li>
            </ul>
            <div style="margin-top: 20px;" th:if="${list.questionType== '2'}">
                <label  class="col-sm-3 control-label">解决方案：</label>
                <div class="col-sm-8">
                    <textarea  th:text="${list.questionInfo}" class="form-control" type="text" readonly></textarea>
                </div>
                <label class="col-sm-3 control-label">附件：</label>
                <div class="col-sm-8">
                    <ul th:each="file,fileStat : ${list.files}" style="padding-left: 0px;">
                        <img class="question_imgFile" th:src="${file.fileId}" th:if="${file.fileType=='png'||file.fileType=='jpg'}" data-id="${file.id}">
                        <img th:src="@{/img/tb_word.png}" th:if="${file.fileType=='docx'||file.fileType=='doc'}">
                        <img th:src="@{/img/tb_excel.png}" th:if="${file.fileType=='xls'||file.fileType=='xlsx'}">
                        <img th:src="@{/img/tb_zip.png}" th:if="${file.fileType=='zip'||file.fileType=='rar'}">
                        <img th:src="@{/img/tb_ppt.png}" th:if="${file.fileType=='ppt'||file.fileType=='pptx'}">
                    </ul>
                </div>

            </div>
            <div style="margin-top: 20px;" th:if="${list.questionType== '1'}">
                <label class="col-sm-3 control-label">追加问题描述：</label>
                <div class="col-sm-8">
                    <textarea  name="questionInfo"  th:text="${list.questionInfo}" class="form-control" type="text" readonly></textarea>
                </div>

                <label class="col-sm-3 control-label">附件：</label>
                <div class="col-sm-8">
                    <ul th:each="file,fileStat : ${dfQuestion.files}" style="padding-left: 0px;">
                        <img class="question_imgFile" th:src="${file.fileId}" th:if="${file.fileType=='png'||file.fileType=='jpg'}" data-id="${file.id}">
                        <img th:src="@{/img/tb_word.png}" th:if="${file.fileType=='docx'||file.fileType=='doc'}">
                        <img th:src="@{/img/tb_excel.png}" th:if="${file.fileType=='xls'||file.fileType=='xlsx'}">
                        <img th:src="@{/img/tb_zip.png}" th:if="${file.fileType=='zip'||file.fileType=='rar'}">
                        <img th:src="@{/img/tb_ppt.png}" th:if="${file.fileType=='ppt'||file.fileType=='pptx'}">
                    </ul>
                </div>
            </div>
        </div>

    </form>
    <div class="form-group" style="overflow: hidden; padding-bottom: 15px; border-bottom: dashed 1px #ec0000 ; ">
        <label class="col-sm-3 control-label"></label>
        <div class="col-sm-8">
            <button onclick="resolved()" style="width: 120px; height: 30px; border: 0; background: #55abef; color: #fff; border-radius: 12px; float: right; font-size: 16px; line-height: 30px;">解&emsp;决</button>
        </div>
    </div>



    <div>
        <ul>
            <li class="wttw_head">追加问题描述</li>
        </ul>
    </div>

    <form class="form-horizontal m" id="form-dfQuestion-submit">


        <div class="form-group">
            <label class="col-sm-3 control-label">问题描述：</label>
            <div class="col-sm-8">
                <textarea id="questionInfo" name="questionInfo"  class="form-control" type="text"></textarea>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">上传附件：</label>
            <input type="file" accept="image/*" onchange="uploadFile()" id="fileUpload" multiple="multiple" style="display: none"/>
            <div class="col-sm-8">
                <ul id="lid"></ul>
                <ul style="padding-left: 0px;">
                    <li><button type="button" class="question_addfail"onclick="upload()"></button></li>
                </ul>

            </div>
        </div>
        <div class="form-group" style="overflow: hidden; padding-bottom: 15px; ">
            <label class="col-sm-3 control-label"></label>
            <div class="col-sm-8">
                <button onclick="submitAgain(a)" style="width: 120px; height: 30px; border: 0; background: #55abef; color: #fff; border-radius: 12px; float: right; font-size: 16px; line-height: 30px;">提&emsp;交</button>
            </div>
        </div>

    </form>
</div>


<div th:include="include::footer"></div>
<script src="/js/star/jquery.raty.min.js" th:src="@{/js/star/jquery.raty.min.js}"></script>
<script type="text/javascript">
    var a = $("#id").val();
    var id = $("#id").val();
    var prefix = ctx + "question/dfApprove";
    var prefis = ctx + "question/dfFile"
    var preFile = "http://211.149.205.33:18080/file/";
    $("#form-dfQuestion-edit").validate({
        rules:{
            xxxx:{
                required:true,
            },
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-dfQuestion-edit').serialize(),saveCallback);
        }
    }
    function saveCallback(result) {
        var question_id = result.data;
        addFile(question_id) //上传
    }
    function upload() {
        $("#fileUpload").click()
    }
    //再次提交问题
    function submitAgain(id) {
        $.operate.save(ctx + "question/dfQuestionChild/submitAgain/"+id, $('#form-dfQuestion-submit').serialize(),addFile);
        // $.modal.close();
    }
    //解决问题
    function resolved() {
        // $.operate.save(ctx + "question/dfQuestion/passApprove", $('#form-dfQuestion-edit').serialize());
        // $.modal.close();

        $.modal.open("问题评论",ctx + "question/dfQuestion/comment/"+id);
    }

    $(function () {
        $(".question_imgFile").width($(".col-sm-8").width());

    })
    var arr =[];  //定义一个数组
    function uploadFile(){		 //
        var file = $("#fileUpload").get(0).files[0];
        if(file != undefined){
            var formData = new FormData();
            formData.append("files", file);
            $.ajax({
                url:preFile+"mulitiupload",
                type: "POST",
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function(resp) {
                    var model=new Object();
                    model.fileId =resp[0].fileid; //文件id
                    model.fileName =resp[0].name;//文件名称
                    var index = model.fileName.lastIndexOf(".");
                    var suffix = model.fileName.substring(index+1);
                    model.fileType =suffix; //文件类型
                    arr.push(model);
                    var downUrl="http://211.149.205.33:18080/file/down/"+model.fileId;
                    if(suffix=="png" || suffix=="jpg"){
                        $("#lid").append('<img src="'+preFile+"img/"+model.fileId+'" style="width: 66px;height: 66px" id="img0" >').append(" ");
                    }
                    if(suffix=="xls" || suffix=="xlsx"){
                        $("#lid").append('<a href="'+downUrl+'"><img src="'+preFile+"img/"+190916001140350+'" style="width: 66px;height: 66px" id="img0"></a>').append(" ");
                    }
                    if(suffix=="docx"|| suffix=="doc"){
                        $("#lid").append('<a href="'+downUrl+'"><img src="'+preFile+"img/"+190916001206935+'" style="width: 66px;height: 66px" id="img0" ></a>').append(" ");
                    }
                    if(suffix=="zip" || suffix=="rar"){
                        $("#lid").append('<a href="'+downUrl+'"><img src="'+preFile+"img/"+190916001125877+'" style="width: 66px;height: 66px" id="img0" ></a>').append(" ");
                    }
                    if(suffix=="ppt" || suffix=="pptx"){
                        $("#lid").append('<a href="'+downUrl+'"><img src="'+preFile+"img/"+190916091106432+'" style="width: 66px;height: 66px" id="img0" ></a>').append(" ");
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("附件上传失败。");
                }
            });
        } else {
            $.modal.alertWarning("服务出现错误 。联系管理员 ");
        }
    };


    function addFile(question_id){
        $.ajax({
            url:prefis+"/saveFile",
            type: "POST",
            data: {questionId:question_id,array:JSON.stringify(arr)},
            dataType:"json",
            success: function(resp) {

            }
        });
    }
</script>
</body>
</html>
